﻿<!DOCTYPE HTML>
<html xmlns:th="http://www.w3.org/1999/xhtml" xmlns:if="http://www.w3.org/1999/xhtml">
<!-- 插入公共模板 _meta -->
<head th:insert="../templates/admin/common/_meta :: common_meta"></head>
<body>

<!-- 插入公共模板 _header -->
<div th:replace="../templates/admin/common/_header :: common_header"></div>

<!-- 插入公共模板 _menu -->
<div th:replace="../templates/admin/common/_menu :: common_menu"></div>

<section class="Hui-article-box">
	<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 商品管理 <span class="c-gray en">&gt;</span> 种类列表<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
	<div class="Hui-article">
		<article class="cl pd-20">
			<div class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l">
					<a href="javascript:;" onclick="goodsCategory_add('添加种类','goGoodsCategoryAdd','','510')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加种类</a>
				</span>
				<span class="r">共有数据：<strong th:text="${goodsCategoryVOList.size()}"></strong> 条</span>
			</div>
			<div class="mt-20">
				<table class="table table-border table-bordered table-hover table-bg table-sort">
					<thead>
						<tr class="text-c">
							<th width="25"><input type="checkbox" ></th>
							<th width="40">序号</th>
							<th width="100">父种类名称</th>
							<th width="100">种类名称</th>
							<th width="180">简要描述</th>
							<th width="70">创建者</th>
							<th width="130">创建时间</th>
							<th width="130">修改时间</th>
							<th width="70">状态</th>
							<th width="100">操作</th>
						</tr>
					</thead>
					<tbody>
						<tr class="text-c" th:each="goodsCategoryVO,var : ${goodsCategoryVOList}">
							<td><input type="checkbox" th:value="${goodsCategoryVO.categoryId}" name="categoryId"></td>
							<td th:text="${var.count}"></td>
							<td th:text="${goodsCategoryVO.parentCategoryName}"></td>
							<td th:text="${goodsCategoryVO.categoryName}"></td>
							<td th:text="${goodsCategoryVO.simpleDescribe}"></td>
							<td th:text="${goodsCategoryVO.adminName}"></td>
							<td th:with="createTime=${goodsCategoryVO.createTime}" th:text="${#dates.format(createTime, 'yyyy-MM-dd HH:mm:ss')}"></td>
							<td th:with="updateTime=${goodsCategoryVO.updateTime}" th:text="${#dates.format(updateTime, 'yyyy-MM-dd HH:mm:ss')}"></td>
							<td class="td-status">
								<span class="label label-success radius" th:if="${goodsCategoryVO.state == 1}">已启用</span>
								<span class="label label-defaunt radius" th:if="${goodsCategoryVO.state == 2}">已停用</span>
							</td>
							<td class="td-manage">
								<a title="停用" href="javascript:;" th:if="${goodsCategoryVO.state == 1}" style="text-decoration:none" th:onClick="|goodsCategory_stop(this,${goodsCategoryVO.categoryId},'stop')|"><i class="Hui-iconfont">&#xe631;</i></a>
								<a title="启用" href="javascript:;" th:if="${goodsCategoryVO.state == 2}" style="text-decoration:none" th:onClick="|goodsCategory_start(this,${goodsCategoryVO.categoryId},'start')|"><i class="Hui-iconfont">&#xe6e1;</i></a>
								<a title="编辑" href="javascript:;" th:onclick="|goodsCategory_edit('编辑','goGoodsCategoryEdit',${goodsCategoryVO.categoryId},'','510')|" style="text-decoration:none" class="ml-5"><i class="Hui-iconfont">&#xe6df;</i></a>
								<a title="删除" href="javascript:;" th:onclick="|goodsCategory_del(this,${goodsCategoryVO.categoryId})|" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</article>
	</div>
</section>

<!-- 插入公共模版 _footer -->
<div th:replace="../templates/admin/common/_footer :: common_footer"></div>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="../../lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" th:inline="none">

	/*商品种类-添加*/
	function goodsCategory_add(title,url,w,h){
		layer_show(title,url,w,h);
	}

	/*商品种类-删除*/
	function goodsCategory_del(obj,categoryId){
		layer.confirm('确认要删除吗？',function(index){
			$.ajax({
				type: "GET",
				dateType: "json",
				url: "doGoodsCategoryDelete"+"?categoryId="+categoryId,
				success: function (result) {
					if(result.flag = "true") {
						$(obj).parents("tr").remove();
						layer.msg('已删除!',{icon:1,time:1000});
					} else {
						layer.msg('删除失败!',{icon: 2,time:1000});
					}
				},
				error: function (err) {
					layer.msg('请求异常!',{icon: 2,time:1000})
				}
			});

		});
	}

	/*商品种类-停用*/
	function goodsCategory_stop(obj,categoryId,state){
		layer.confirm('确认要停用吗？',function(index){
			$.ajax({
				type: "GET",
				dateType: "json",
				url: "doGoodsCategoryState"+"?categoryId="+categoryId + "&state=" + state,
				success: function (result) {
					if(result.flag = "true") {
						$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="goodsCategory_start(this,'+categoryId+',\'start\')" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe6e1;</i></a>');
						$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已停用</span>');
						$(obj).remove();
						layer.msg('已停用!',{icon: 5,time:1000});
					} else {
						layer.msg('停用失败!',{icon: 2,time:1000});
					}
				},
				error: function (err) {
					layer.msg('请求异常!',{icon: 2,time:1000})
				}
			});
		});
	}

	/*商品种类-启用*/
	function goodsCategory_start(obj,categoryId,state){
		layer.confirm('确认要启用吗？',function(index){
			$.ajax({
				type: "GET",
				dateType: "json",
				url: "doGoodsCategoryState" + "?categoryId=" + categoryId + "&state=" + state,
				success: function (result) {
					if(result.flag = "true") {
						$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="goodsCategory_stop(this,'+categoryId+',\'stop\')" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>');
						$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
						$(obj).remove();
						layer.msg('已启用!',{icon: 6,time:1000});
					} else {
						layer.msg('启用失败!',{icon: 2,time:1000});
					}
				},
				error: function (err) {
					layer.msg('请求异常!',{icon: 2,time:1000})
				}
			});
		});
	}

	/*商品种类-编辑*/
	function goodsCategory_edit(title,url,categoryId,w,h){
		url = url + "?categoryId=" + categoryId;
		layer_show(title,url,w,h);
	}

	/* 表格配置 */
	$(function(){
		$('.table-sort').dataTable({
			"aaSorting": [[ 1, "asc" ]],//默认第几个排序
			"bStateSave": true,//状态保存
			"aoColumnDefs": [
			  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
			  {"orderable":false,"aTargets":[0,8,9]}// 制定列不参与排序
			]
		});
	});

</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>